package com.ticket.web.controller.yanchu;

import com.ticket.common.annotation.Log;
import com.ticket.common.core.controller.BaseController;
import com.ticket.common.core.page.TableDataInfo;
import com.ticket.common.enums.BusinessType;
import com.ticket.common.exception.base.BaseException;
import com.ticket.common.utils.Const;
import com.ticket.common.utils.StringUtils;
import com.ticket.common.utils.poi.ExcelUtil;
import com.ticket.framework.web.service.TokenService;
import com.ticket.system.domain.YanchuConsumeRecord;
import com.ticket.system.domain.vo.ConsumeRecordVO;
import com.ticket.system.service.IYanchuConsumeRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 消费记录（包含充值）Controller
 * 
 * @author ruoyi
 * @date 2023-12-12
 */
@Api("消费记录（包含充值）")
@RestController
@RequestMapping("/system/record")
public class YanchuConsumeRecordController extends BaseController
{
    @Autowired
    private IYanchuConsumeRecordService yanchuConsumeRecordService;
    @Autowired
    private TokenService tokenService;


    @ApiOperation("查询充值记录列表（pc 集团管理员和财务管理员）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime",value = "开始时间",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "endTime",value = "结束时间",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "status",value = "充值状态 0：成功；1：失败",dataTypeClass = Integer.class,dataType = "Integer"),
            @ApiImplicitParam(name = "orderNo",value = "充值订单号",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "keyName",value = "模糊匹配字段",dataTypeClass = String.class,dataType = "String"),
    })
    @PreAuthorize("@ss.hasPermi('system:record:rechargeList')")
    @GetMapping("/rechargeList")
    public TableDataInfo rechargeList(String startTime,String endTime,Integer status,String orderNo,String keyName)
    {
        startPage();
        List<ConsumeRecordVO> list = yanchuConsumeRecordService.rechargeList(startTime,endTime,status,orderNo,keyName);
        return getDataTable(list);
    }

    @ApiOperation("查询消费记录列表（pc 集团管理员和财务管理员）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime",value = "开始时间",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "endTime",value = "结束时间",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "operaId",value = "剧院id",dataTypeClass = Long.class,dataType = "long"),
            @ApiImplicitParam(name = "orderNo",value = "消费（退款）订单号",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "keyName",value = "模糊匹配字段",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "cardNum",value = "观演卡卡号",dataTypeClass = String.class,dataType = "String"),
            @ApiImplicitParam(name = "type",value = "2:储值；1：观演卡",dataTypeClass = String.class,dataType = "String"),
    })
    @PreAuthorize("@ss.hasPermi('system:record:consumeList')")
    @GetMapping("/consumeList")
    public TableDataInfo consumeList(String startTime,String endTime,Integer operaId,String orderNo,String keyName,String cardNum,Integer type)
    {
        startPage();
        List<ConsumeRecordVO> list = yanchuConsumeRecordService.consumeList(startTime,endTime,operaId,orderNo,keyName,cardNum,type);
        return getDataTable(list);
    }

    @ApiOperation("小程序用户消费记录（观演卡 储值卡）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardNum",value = "观演卡主键id",dataType = "long",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "type",value = " 1：观演卡；2：储存卡",dataType = "int",dataTypeClass = Integer.class),
    })
    @GetMapping("/mobileList")
    public TableDataInfo mobileList(String cardNum, Integer type, HttpServletRequest request){
        startPage();
        if (Const.ONE.equals(type) && StringUtils.isEmpty(cardNum)){
            throw new BaseException("观演卡数据缺失");
        }
        return getDataTable(yanchuConsumeRecordService.mobileList(cardNum,type,tokenService.getLoginUser(request).getUser().getUserId()));
    }

    /**
     * 导出消费记录（包含充值）列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "消费记录（包含充值）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YanchuConsumeRecord yanchuConsumeRecord)
    {
        List<YanchuConsumeRecord> list = yanchuConsumeRecordService.selectYanchuConsumeRecordList(yanchuConsumeRecord);
        ExcelUtil<YanchuConsumeRecord> util = new ExcelUtil<YanchuConsumeRecord>(YanchuConsumeRecord.class);
        util.exportExcel(response, list, "消费记录（包含充值）数据");
    }
}
